<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Example 8.3: Bounding correlation coefficients</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/cvxbook/Ch08_geometric_probs/html/ex_8_3.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Example 8.3: Bounding correlation coefficients</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Joelle Skaf - 10/09/05</span>
<span class="comment">%</span>
<span class="comment">% Let C be a correlation matrix. Given lower and upper bounds on</span>
<span class="comment">% some of the angles (or correlation coeff.), find the maximum and minimum</span>
<span class="comment">% possible values of rho_14 by solving 2 SDP's</span>
<span class="comment">%           minimize/maximize   rho_14</span>
<span class="comment">%                        s.t.   C &gt;=0</span>
<span class="comment">%                               0.6 &lt;= rho_12 &lt;=  0.9</span>
<span class="comment">%                               0.8 &lt;= rho_13 &lt;=  0.9</span>
<span class="comment">%                               0.5 &lt;= rho_24 &lt;=  0.7</span>
<span class="comment">%                              -0.8 &lt;= rho_34 &lt;= -0.4</span>

n = 4;

<span class="comment">% Upper bound SDP</span>
fprintf(1,<span class="string">'Solving the upper bound SDP ...'</span>);

cvx_begin <span class="string">sdp</span>
    variable <span class="string">C1(n,n)</span> <span class="string">symmetric</span>
    maximize ( C1(1,4) )
    C1 &gt;= 0;
    diag(C1) == ones(n,1);
    C1(1,2) &gt;= 0.6;
    C1(1,2) &lt;= 0.9;
    C1(1,3) &gt;= 0.8;
    C1(1,3) &lt;= 0.9;
    C1(2,4) &gt;= 0.5;
    C1(2,4) &lt;= 0.7;
    C1(3,4) &gt;= -0.8;
    C1(3,4) &lt;= -0.4;
cvx_end

fprintf(1,<span class="string">'Done! \n'</span>);

<span class="comment">% Lower bound SDP</span>
fprintf(1,<span class="string">'Solving the lower bound SDP ...'</span>);

cvx_begin <span class="string">sdp</span>
    variable <span class="string">C2(n,n)</span> <span class="string">symmetric</span>
    minimize ( C2(1,4) )
    C2 &gt;= 0;
    diag(C2) == ones(n,1);
    C2(1,2) &gt;= 0.6;
    C2(1,2) &lt;= 0.9;
    C2(1,3) &gt;= 0.8;
    C2(1,3) &lt;= 0.9;
    C2(2,4) &gt;= 0.5;
    C2(2,4) &lt;= 0.7;
    C2(3,4) &gt;= -0.8;
    C2(3,4) &lt;= -0.4;
cvx_end

fprintf(1,<span class="string">'Done! \n'</span>);
<span class="comment">% Displaying results</span>
disp(<span class="string">'--------------------------------------------------------------------------------'</span>);
disp([<span class="string">'The minimum and maximum values of rho_14 are: '</span> num2str(C2(1,4)) <span class="string">' and '</span> num2str(C1(1,4))]);
disp(<span class="string">'with corresponding correlation matrices: '</span>);
disp(C2)
disp(C1)
</pre>
<a id="output"></a>
<pre class="codeoutput">
Solving the upper bound SDP ... 
Calling SDPT3: 18 variables, 6 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints =  6
 dim. of sdp    var  =  4,   num. of sdp  blk  =  1
 dim. of linear var  =  8
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
   HKM      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|5.0e-01|8.7e+00|1.2e+03| 5.000000e+01  0.000000e+00| 0:0:00| chol  1  1 
 1|1.000|0.963|4.7e-07|4.0e-01|8.6e+01| 3.764390e+01  1.045278e-01| 0:0:00| chol  1  1 
 2|0.930|0.962|2.4e-06|2.4e-02|1.2e+01| 9.519382e+00  5.545477e-02| 0:0:00| chol  1  1 
 3|0.979|1.000|1.4e-07|9.0e-04|6.4e-01| 6.821346e-01  4.804692e-02| 0:0:00| chol  1  1 
 4|1.000|1.000|5.8e-08|9.0e-05|1.3e-01| 3.354711e-01  2.021144e-01| 0:0:00| chol  1  1 
 5|0.945|0.990|4.5e-09|9.9e-06|6.7e-03| 2.357452e-01  2.290535e-01| 0:0:00| chol  1  1 
 6|0.891|1.000|9.7e-09|9.0e-07|9.1e-04| 2.306737e-01  2.297716e-01| 0:0:00| chol  1  1 
 7|1.000|1.000|5.5e-09|9.2e-08|8.9e-05| 2.299788e-01  2.298904e-01| 0:0:00| chol  1  1 
 8|0.966|0.983|8.2e-10|2.6e-09|2.9e-06| 2.299114e-01  2.299086e-01| 0:0:00| chol  1  1 
 9|1.000|1.000|3.7e-09|1.6e-10|6.1e-07| 2.299095e-01  2.299089e-01| 0:0:00| chol  1  1 
10|1.000|1.000|8.4e-12|2.5e-10|3.0e-08| 2.299091e-01  2.299091e-01| 0:0:00| chol  1  1 
11|1.000|1.000|4.0e-13|1.7e-12|5.0e-10| 2.299091e-01  2.299091e-01| 0:0:00|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 11
 primal objective value =  2.29909084e-01
 dual   objective value =  2.29909083e-01
 gap := trace(XZ)       = 4.98e-10
 relative gap           = 3.41e-10
 actual relative gap    = 3.35e-10
 rel. primal infeas     = 3.95e-13
 rel. dual   infeas     = 1.68e-12
 norm(X), norm(y), norm(Z) = 2.8e+00, 5.7e-01, 2.8e+00
 norm(A), norm(b), norm(C) = 5.5e+00, 2.0e+00, 3.8e+00
 Total CPU time (secs)  = 0.17  
 CPU time per iteration = 0.02  
 termination code       =  0
 DIMACS: 4.0e-13  0.0e+00  3.2e-12  0.0e+00  3.4e-10  3.4e-10
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.229909
 
Done! 
Solving the lower bound SDP ... 
Calling SDPT3: 18 variables, 6 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints =  6
 dim. of sdp    var  =  4,   num. of sdp  blk  =  1
 dim. of linear var  =  8
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
   HKM      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|5.0e-01|8.7e+00|1.2e+03| 5.000000e+01  0.000000e+00| 0:0:00| chol  1  1 
 1|1.000|0.965|4.6e-07|3.9e-01|8.5e+01| 3.764990e+01  1.075756e-01| 0:0:00| chol  1  1 
 2|0.927|1.000|2.3e-06|9.0e-03|9.9e+00| 9.200175e+00  1.305318e-01| 0:0:00| chol  1  1 
 3|0.897|1.000|2.9e-07|9.0e-04|1.0e+00| 1.182476e+00  1.678502e-01| 0:0:00| chol  1  1 
 4|1.000|0.662|4.2e-08|3.6e-04|6.2e-01| 9.449252e-01  3.321156e-01| 0:0:00| chol  1  1 
 5|0.933|1.000|4.1e-09|9.0e-06|4.2e-02| 4.233944e-01  3.816576e-01| 0:0:00| chol  1  1 
 6|0.963|1.000|1.1e-09|9.0e-07|4.5e-03| 3.962889e-01  3.917716e-01| 0:0:00| chol  1  1 
 7|0.960|0.992|9.3e-10|9.7e-08|2.6e-04| 3.930398e-01  3.927797e-01| 0:0:00| chol  1  1 
 8|0.966|0.985|6.9e-10|1.1e-08|8.3e-06| 3.928279e-01  3.928197e-01| 0:0:00| chol  1  1 
 9|1.000|1.000|2.2e-09|1.4e-10|1.6e-06| 3.928215e-01  3.928199e-01| 0:0:00| chol  1  1 
10|1.000|1.000|2.1e-11|2.1e-10|2.3e-08| 3.928203e-01  3.928203e-01| 0:0:00|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 10
 primal objective value =  3.92820340e-01
 dual   objective value =  3.92820317e-01
 gap := trace(XZ)       = 2.32e-08
 relative gap           = 1.30e-08
 actual relative gap    = 1.25e-08
 rel. primal infeas     = 2.14e-11
 rel. dual   infeas     = 2.08e-10
 norm(X), norm(y), norm(Z) = 2.2e+00, 5.8e-01, 2.8e+00
 norm(A), norm(b), norm(C) = 5.5e+00, 2.0e+00, 3.8e+00
 Total CPU time (secs)  = 0.15  
 CPU time per iteration = 0.01  
 termination code       =  0
 DIMACS: 2.1e-11  0.0e+00  4.0e-10  0.0e+00  1.2e-08  1.3e-08
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -0.39282
 
Done! 
--------------------------------------------------------------------------------
The minimum and maximum values of rho_14 are: -0.39282 and 0.22991
with corresponding correlation matrices: 
    1.0000    0.6000    0.8433   -0.3928
    0.6000    1.0000    0.3322    0.5000
    0.8433    0.3322    1.0000   -0.5311
   -0.3928    0.5000   -0.5311    1.0000

    1.0000    0.7127    0.8000    0.2299
    0.7127    1.0000    0.3120    0.5827
    0.8000    0.3120    1.0000   -0.4000
    0.2299    0.5827   -0.4000    1.0000

</pre>
</div>
</body>
</html>